<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/27 0027
 * Time: 8:51
 */
namespace app\index\model;
use think\Db;

class GetData extends Db
{
    /**获取
     * @param $str
     * @return $this
     */
    static public function Get($str){
        return Db::view($str)
            ->view('document',"*","document.id=$str.uid",'left');
    }

    /**获取配置信息
     * @return array
     */
    static public function System(){
        $data = Db::name('conf')->select();
        $datas =[];
        foreach ($data as $value){
            $datas[$value['enname']] = $value['value'];
        }
        return $datas;
    }

    /**获取关键词
     * @param null $array
     * @return array
     */
    static public function KeyWord($array=null){
        $data = ['keywords'=>'','description'=>''];
        if($array){
            if(is_array($array)){
                foreach ($array as $value){
                    if(isset($value['description'])){
                        $data['description'] .= $value['description'].';';
                    }
                    if(isset($value['keywords'])){
                        $data['keywords'] .= $value['keywords'].';';
                    }
                }
            }else{
                if(isset($array['description'])){
                    $data['description'] .= $array['description'].';';
                }
                if(isset($array['keywords'])){
                    $data['keywords'] .= $array['keywords'].';';
                }
            }
        }else{
            $array = GetData::System();
            if(isset($array['description'])){
                $data['description'] .= $array['description'].';';
            }
            if(isset($array['keywords'])){
                $data['keywords'] .= $array['keywords'].';';
            }
        }
        if(!$data['keywords']){
            $array = GetData::System();
            if(isset($array['description'])){
                $data['description'] .= $array['description'].';';
            }
        }
        if(!$data['description']){
            $array = GetData::System();
            if(isset($array['keywords'])){
                $data['keywords'] .= $array['keywords'].';';
            }
        }
        return $data;
    }
}